package com.zhs.gccs.dao;

import com.zhs.gccs.base.DbConstants;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

public class XUtilsManager {

    private volatile static XUtilsManager xUtilsManager;

    private DbManager dbManager;

    private XUtilsManager() {
    }

    public static XUtilsManager getInstance() {
        if (xUtilsManager == null) {
            synchronized (XUtilsManager.class) {
                if (xUtilsManager == null) {
                    xUtilsManager = new XUtilsManager();
                }
            }
        }
        return xUtilsManager;
    }

    public DbManager getDbManager() {
        if (dbManager == null) {
            initDbManager();
        }
        return dbManager;
    }

    public void DropDbManager() {
        if (dbManager != null) {
            try {
                dbManager.dropDb();
            } catch (DbException e) {
                e.printStackTrace();
            }
        }
    }

    private void initDbManager() {
        try {
            DbManager.DaoConfig config = new DbManager.DaoConfig()
//                    .setDbDir(new File(SharedPrefHelper.getInstance().getAppSdCardPath()))
                    .setDbName(DbConstants.TAG);
            dbManager = x.getDb(config);
        } catch (DbException e) {
            e.printStackTrace();
        }
    }
}
